package com.xty.itgroup.tech05tytex.Mapper;

import com.xty.itgroup.tech05tytex.Databean.Bean03AxisDetail;
import com.xty.itgroup.tech05tytex.Databean.Bean03AxisMain;
import com.xty.itgroup.tech05tytex.Databean.Bean03Company;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @program: base-product
 * @description:
 * @author: JinHaonan
 * @create: 2020/10/10 15:23
 **/
@Mapper
public interface Mapper03Axis {
    @Insert("insert into tytex03axis_main(axis_id,axis_carddate,weave_sum,defect_info,company_id,order_date,order_id,weave_name,catch_warp,warp_rate,weft_rate,axis_count,create_time,plan_count_jsum,plan_count1_jsum,real_count_jsum,plan_count_wsum,plan_count1_wsum,real_count_wsum) " +
            "VALUES(#{axis_id},#{axis_carddate},#{weave_sum},#{defect_info},#{company_id},#{order_date},#{order_id},#{weave_name},#{catch_warp},#{warp_rate},#{weft_rate},#{axis_count},Now(),#{plan_count_jsum},#{plan_count1_jsum},#{real_count_jsum},#{plan_count_wsum},#{plan_count1_wsum},#{real_count_wsum}) ")
    @Options(useGeneratedKeys = true, keyProperty = "axis_main_id", keyColumn = "axis_main_id")
    public abstract void addAxisMain(Bean03AxisMain axiss);
    @Insert("<script>insert into tytex03axis_detail(axis_main_id,jw_type,yarn_id,batch_id,plan_count,plan_count1,use_count,weight,create_time) VALUES " +
            "<foreach collection='axiss' item='axis' separator=','>" +
            "(" +
            "#{axismainid},#{type},#{axis.yarn_id},#{axis.batch_id},#{axis.plan_count},#{axis.plan_count1},#{axis.use_count},#{axis.weight},Now()" +
            ")" +
            "</foreach></script>")
    public abstract void addAxisDetail(@Param("axiss") List<Bean03AxisDetail> axiss, String type, int axismainid);
    @Select("SELECT cam.axis_main_id,cam.axis_id,DATE_FORMAT(cam.axis_carddate, '%Y-%m-%d') axis_carddate,cam" +
            ".weave_sum,cam.defect_info,cam.company_id,DATE_FORMAT(cam.order_date, '%Y-%m-%d') order_date,cam" +
            ".order_id,cam.weave_name,cam.catch_warp,cam.warp_rate,cam.weft_rate,cam.axis_count,DATE_FORMAT(cam" +
            ".create_time, '%Y-%m-%d') create_time,cam" +
            ".plan_count_jsum,cam.plan_count1_jsum,cam.real_count_jsum,cam.plan_count_wsum,cam.plan_count1_wsum,cam" +
            ".real_count_wsum,cc.company_name FROM tytex03axis_main cam,view_company cc  " +
            "where cc.original_id=cam.company_id and cam.order_id like #{orderid} and cam.weave_name like " +
            "#{weavename} and IF(#{companyid}!=-1,cam.company_id=#{companyid},1=1) order by create_time desc")
    public abstract List<Map<String, Object>> listAxisCards(String orderid, String weavename, int companyid);

    @Select("SELECT cam.axis_main_id,cam.axis_id,DATE_FORMAT(cam.axis_carddate, '%Y-%m-%d') axis_carddate,cam" +
            ".weave_sum,cam.defect_info,cam.company_id,DATE_FORMAT(cam.order_date, '%Y-%m-%d') " +
            "order_date,cam.order_id,cam.weave_name,cam.catch_warp,cam.warp_rate,cam.weft_rate,cam.axis_count," +
            "DATE_FORMAT(cam.create_time, '%Y-%m-%d') create_time,cam.plan_count_jsum,cam.plan_count1_jsum,cam.real_count_jsum,cam.plan_count_wsum,cam" +
            ".plan_count1_wsum,cam.real_count_wsum,cc.company_name FROM tytex03axis_main cam,view_company cc where cc" +
            ".original_id=cam" +
            ".company_id and cam.axis_main_id=#{mainid}")
    public abstract Map<String, Object> getMainById(int mainid);


    @Select("SELECT cad.*,cy.yarn_name,cy.yarn_tech FROM tytex03axis_detail cad,quote01yarn_new cy where " +
            "axis_main_id=#{axismainid} and cy.yarn_id=cad.yarn_id")
    public abstract List<Map<String, Object>> getDetailByAxisId(int axismainid);

    @Update("UPDATE tytex03axis_main SET axis_carddate=#{axis_carddate}  ,weave_sum=#{weave_sum} ,axis_count=#{axis_count},catch_warp=#{catch_warp},defect_info=#{defect_info}," +
            "plan_count_jsum=#{plan_count_jsum},plan_count1_jsum=#{plan_count1_jsum},real_count_jsum=#{real_count_jsum},plan_count_wsum=#{plan_count_wsum},plan_count1_wsum=#{plan_count1_wsum},real_count_wsum=#{real_count_wsum}" +
            "   WHERE axis_main_id=#{axis_main_id}")
    public abstract void updateAxisMain(Bean03AxisMain bam);

    @Delete("delete from tytex03axis_detail where axis_main_id=#{mainid}")
    public abstract void deleteAxisdetail(int mainid);

    @Delete("delete from tytex03axis_main where axis_main_id=#{mainid}")
    void deleteAxisMain(int mainid);
    @Select("SELECT cf21.*,cy.yarn_name,yarn_tech FROM `quote02bom_detail` cf21,quote01yarn_new cy where " +
            "weave_name=#{weave_name}  and cf21.yarn_id=cy.yarn_id")
    public abstract List<Map<String, Object>> getAxisLines(String weave_name);

    @Select("select original_id,company_name from view_company where company_name like #{company_name}")
    public abstract List<Bean03Company> listCompany(String company_name);
}
